﻿namespace jzgl.Windows
{
    using jzgl.Controller;
    using jzgl.Model;
    using System;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Windows.Forms;

    public class DesignerInfo : Form
    {
        private Button btn_add_edit;
        private Button btn_Cancel;
        private Button btn_reset;
        private Button btn_ShanChu;
        private Button btn_TianJia;
        private Button btn_XiuGai;
        private DataGridViewTextBoxColumn Column1;
        private DataGridViewTextBoxColumn Column2;
        private DataGridViewTextBoxColumn Column3;
        private IContainer components = null;
        private DataGridView dataGridView1;
        private Designer des = new Designer();
        private DesignerDB desDB = new DesignerDB();
        private GroupBox groupBox1;
        private GroupBox groupBox2;
        private GroupBox groupBox3;
        private Label label1;
        private Label label2;
        private Panel panel1;
        private int t = 0;
        private DataTable table = null;
        private TextBox txt_name;
        private TextBox txt_remark;

        public DesignerInfo()
        {
            this.InitializeComponent();
            this.groupBox2.Visible = true;
            this.groupBox3.Visible = false;
            this.Data_bind();
        }

        private void btn_add_edit_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.txt_name.Text.Trim().Equals(""))
                {
                    MessageBox.Show("设计师姓名不能为空！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    this.des._DesignerName = this.txt_name.Text.Trim();
                    this.des._DesignerRemark = this.txt_remark.Text.Trim();
                    if ((this.t == 1) && (this.desDB.Add_Designer(this.des) != 0))
                    {
                        MessageBox.Show("已添加！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                        this.t = 0;
                    }
                    if (this.t == 2)
                    {
                        this.des._DesignerId = int.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString());
                        if (this.desDB.Update_Designer(this.des) != 0)
                        {
                            MessageBox.Show("修改成功！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                            this.t = 0;
                        }
                    }
                    this.groupBox2.Visible = true;
                    this.groupBox3.Visible = false;
                    this.Data_bind();
                    this.dataGridView1.Enabled = true;
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_Cancel_Click(object sender, EventArgs e)
        {
            try
            {
                this.groupBox3.Visible = false;
                this.groupBox2.Visible = true;
                this.txt_remark.Text = this.txt_name.Text = "";
                this.dataGridView1.Enabled = true;
            }
            catch (Exception)
            {
            }
        }

        private void btn_reset_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.t == 1)
                {
                    this.txt_name.Text = this.txt_remark.Text = "";
                }
                if (this.t == 2)
                {
                    this.txt_name.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
                    this.txt_remark.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_ShanChu_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.Rows.Count == 0)
                {
                    MessageBox.Show("没有数据可以删除！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                if (this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim().Equals(""))
                {
                    MessageBox.Show("请选择要删除的数据行！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else if (MessageBox.Show("确定要删除吗？", "确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    this.des._DesignerId = int.Parse(this.dataGridView1.CurrentRow.Cells[0].Value.ToString().Trim());
                    if (this.desDB.Delete_Designer(this.des) != 0)
                    {
                        this.Data_bind();
                    }
                }
            }
            catch (Exception)
            {
            }
        }

        private void btn_ShuaXin_Click(object sender, EventArgs e)
        {
            try
            {
                this.dataGridView1.Rows.Clear();
                this.Data_bind();
                this.txt_name.Text = this.txt_remark.Text = "";
                this.dataGridView1.Enabled = true;
            }
            catch (Exception)
            {
            }
        }

        private void btn_TianJia_Click(object sender, EventArgs e)
        {
            try
            {
                this.t = 1;
                this.groupBox2.Visible = false;
                this.groupBox3.Visible = true;
                this.txt_name.Text = this.txt_remark.Text = "";
                this.dataGridView1.Enabled = false;
            }
            catch (Exception)
            {
            }
        }

        private void btn_XiuGai_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.dataGridView1.Rows.Count == 0)
                {
                    MessageBox.Show("没有数据修改！", "提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);
                }
                else
                {
                    this.t = 2;
                    this.groupBox2.Visible = false;
                    this.groupBox3.Visible = true;
                    this.dataGridView1.Enabled = true;
                }
            }
            catch (Exception)
            {
            }
        }

        public void Data_bind()
        {
            try
            {
                this.dataGridView1.Rows.Clear();
                this.table = this.desDB.Show_Designer();
                if (this.table != null)
                {
                    for (int i = 0; i < this.table.Rows.Count; i++)
                    {
                        object[] values = new object[] { this.table.Rows[i][0].ToString(), this.table.Rows[i][1].ToString(), this.table.Rows[i][2].ToString() };
                        this.dataGridView1.Rows.Add(values);
                    }
                }
                this.txt_name.Text = "";
                this.txt_remark.Text = "";
            }
            catch (Exception)
            {
            }
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                this.txt_name.Text = this.dataGridView1.CurrentRow.Cells[1].Value.ToString();
                this.txt_remark.Text = this.dataGridView1.CurrentRow.Cells[2].Value.ToString();
            }
            catch (Exception)
            {
            }
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.panel1 = new Panel();
            this.groupBox3 = new GroupBox();
            this.btn_Cancel = new Button();
            this.btn_reset = new Button();
            this.btn_add_edit = new Button();
            this.txt_remark = new TextBox();
            this.txt_name = new TextBox();
            this.label2 = new Label();
            this.label1 = new Label();
            this.groupBox2 = new GroupBox();
            this.btn_ShanChu = new Button();
            this.btn_XiuGai = new Button();
            this.btn_TianJia = new Button();
            this.groupBox1 = new GroupBox();
            this.dataGridView1 = new DataGridView();
            this.Column1 = new DataGridViewTextBoxColumn();
            this.Column2 = new DataGridViewTextBoxColumn();
            this.Column3 = new DataGridViewTextBoxColumn();
            this.panel1.SuspendLayout();
            this.groupBox3.SuspendLayout();
            this.groupBox2.SuspendLayout();
            this.groupBox1.SuspendLayout();
            ((ISupportInitialize) this.dataGridView1).BeginInit();
            base.SuspendLayout();
            this.panel1.Controls.Add(this.groupBox3);
            this.panel1.Controls.Add(this.groupBox2);
            this.panel1.Controls.Add(this.groupBox1);
            this.panel1.Location = new Point(0, 3);
            this.panel1.Name = "panel1";
            this.panel1.Size = new Size(0x1c8, 0x1cf);
            this.panel1.TabIndex = 0;
            this.groupBox3.Controls.Add(this.btn_Cancel);
            this.groupBox3.Controls.Add(this.btn_reset);
            this.groupBox3.Controls.Add(this.btn_add_edit);
            this.groupBox3.Controls.Add(this.txt_remark);
            this.groupBox3.Controls.Add(this.txt_name);
            this.groupBox3.Controls.Add(this.label2);
            this.groupBox3.Controls.Add(this.label1);
            this.groupBox3.Location = new Point(2, 0x183);
            this.groupBox3.Name = "groupBox3";
            this.groupBox3.Size = new Size(450, 70);
            this.groupBox3.TabIndex = 2;
            this.groupBox3.TabStop = false;
            this.btn_Cancel.Location = new Point(0xfc, 0x26);
            this.btn_Cancel.Name = "btn_Cancel";
            this.btn_Cancel.Size = new Size(0x44, 0x17);
            this.btn_Cancel.TabIndex = 6;
            this.btn_Cancel.Text = "取消";
            this.btn_Cancel.UseVisualStyleBackColor = true;
            this.btn_Cancel.Click += new EventHandler(this.btn_Cancel_Click);
            this.btn_reset.Location = new Point(0xab, 0x26);
            this.btn_reset.Name = "btn_reset";
            this.btn_reset.Size = new Size(0x42, 0x17);
            this.btn_reset.TabIndex = 5;
            this.btn_reset.Text = "重置";
            this.btn_reset.UseVisualStyleBackColor = true;
            this.btn_reset.Click += new EventHandler(this.btn_reset_Click);
            this.btn_add_edit.Location = new Point(90, 0x26);
            this.btn_add_edit.Name = "btn_add_edit";
            this.btn_add_edit.Size = new Size(0x41, 0x17);
            this.btn_add_edit.TabIndex = 4;
            this.btn_add_edit.Text = "确定";
            this.btn_add_edit.UseVisualStyleBackColor = true;
            this.btn_add_edit.Click += new EventHandler(this.btn_add_edit_Click);
            this.txt_remark.Location = new Point(0xc9, 11);
            this.txt_remark.Name = "txt_remark";
            this.txt_remark.Size = new Size(0xe1, 0x15);
            this.txt_remark.TabIndex = 3;
            this.txt_name.Location = new Point(0x26, 11);
            this.txt_name.Name = "txt_name";
            this.txt_name.Size = new Size(0x79, 0x15);
            this.txt_name.TabIndex = 2;
            this.label2.AutoSize = true;
            this.label2.Location = new Point(0xa5, 0x10);
            this.label2.Name = "label2";
            this.label2.Size = new Size(0x29, 12);
            this.label2.TabIndex = 1;
            this.label2.Text = "备注：";
            this.label1.AutoSize = true;
            this.label1.Location = new Point(3, 14);
            this.label1.Name = "label1";
            this.label1.Size = new Size(0x29, 12);
            this.label1.TabIndex = 0;
            this.label1.Text = "姓名：";
            this.groupBox2.Controls.Add(this.btn_ShanChu);
            this.groupBox2.Controls.Add(this.btn_XiuGai);
            this.groupBox2.Controls.Add(this.btn_TianJia);
            this.groupBox2.Location = new Point(2, 0x184);
            this.groupBox2.Name = "groupBox2";
            this.groupBox2.Size = new Size(0x1bf, 0x45);
            this.groupBox2.TabIndex = 1;
            this.groupBox2.TabStop = false;
            this.btn_ShanChu.Location = new Point(260, 0x15);
            this.btn_ShanChu.Name = "btn_ShanChu";
            this.btn_ShanChu.Size = new Size(0x4b, 0x17);
            this.btn_ShanChu.TabIndex = 2;
            this.btn_ShanChu.Text = "删除";
            this.btn_ShanChu.UseVisualStyleBackColor = true;
            this.btn_ShanChu.Click += new EventHandler(this.btn_ShanChu_Click);
            this.btn_XiuGai.Location = new Point(0xb3, 0x15);
            this.btn_XiuGai.Name = "btn_XiuGai";
            this.btn_XiuGai.Size = new Size(0x4b, 0x17);
            this.btn_XiuGai.TabIndex = 1;
            this.btn_XiuGai.Text = "修改";
            this.btn_XiuGai.UseVisualStyleBackColor = true;
            this.btn_XiuGai.Click += new EventHandler(this.btn_XiuGai_Click);
            this.btn_TianJia.Location = new Point(0x62, 0x15);
            this.btn_TianJia.Name = "btn_TianJia";
            this.btn_TianJia.Size = new Size(0x4b, 0x17);
            this.btn_TianJia.TabIndex = 0;
            this.btn_TianJia.Text = "添加";
            this.btn_TianJia.UseVisualStyleBackColor = true;
            this.btn_TianJia.Click += new EventHandler(this.btn_TianJia_Click);
            this.groupBox1.Controls.Add(this.dataGridView1);
            this.groupBox1.Location = new Point(2, 3);
            this.groupBox1.Name = "groupBox1";
            this.groupBox1.Size = new Size(450, 380);
            this.groupBox1.TabIndex = 0;
            this.groupBox1.TabStop = false;
            this.groupBox1.Text = "设计师管理";
            this.dataGridView1.AllowUserToAddRows = false;
            this.dataGridView1.BackgroundColor = SystemColors.ControlLightLight;
            this.dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize;
            this.dataGridView1.Columns.AddRange(new DataGridViewColumn[] { this.Column1, this.Column2, this.Column3 });
            this.dataGridView1.Location = new Point(4, 20);
            this.dataGridView1.Name = "dataGridView1";
            this.dataGridView1.ReadOnly = true;
            this.dataGridView1.RowHeadersWidth = 20;
            this.dataGridView1.RowTemplate.Height = 0x17;
            this.dataGridView1.Size = new Size(0x1bb, 0x160);
            this.dataGridView1.TabIndex = 0;
            this.dataGridView1.CellClick += new DataGridViewCellEventHandler(this.dataGridView1_CellClick);
            this.Column1.HeaderText = "编号";
            this.Column1.Name = "Column1";
            this.Column1.ReadOnly = true;
            this.Column1.Visible = false;
            this.Column1.Width = 70;
            this.Column2.HeaderText = "姓名";
            this.Column2.Name = "Column2";
            this.Column2.ReadOnly = true;
            this.Column2.Width = 180;
            this.Column3.HeaderText = "备注";
            this.Column3.Name = "Column3";
            this.Column3.ReadOnly = true;
            this.Column3.Width = 240;
            base.AutoScaleDimensions = new SizeF(6f, 12f);
            base.AutoScaleMode = AutoScaleMode.Font;
            base.ClientSize = new Size(0x1c5, 0x1d5);
            base.Controls.Add(this.panel1);
            base.FormBorderStyle = FormBorderStyle.FixedSingle;
            base.MaximizeBox = false;
            this.MaximumSize = new Size(0x1cb, 0x1f5);
            this.MinimumSize = new Size(0x1cb, 0x1f5);
            base.Name = "DesignerInfo";
            this.Text = "设计师管理";
            this.panel1.ResumeLayout(false);
            this.groupBox3.ResumeLayout(false);
            this.groupBox3.PerformLayout();
            this.groupBox2.ResumeLayout(false);
            this.groupBox1.ResumeLayout(false);
            ((ISupportInitialize) this.dataGridView1).EndInit();
            base.ResumeLayout(false);
        }
    }
}

